package com.zxj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.common.pojo.R;
import com.zxj.mapper.CarMapper;
import com.zxj.mapper.CarTypeMapper;
import com.zxj.pojo.entity.TbBrand;
import com.zxj.pojo.entity.TbCar;
import com.zxj.pojo.entity.TbCarType;
import com.zxj.pojo.entity.TbCarTypeConfigDetails;
import com.zxj.pojo.vo.TypeVo;
import com.zxj.service.CarTypeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-fifth
 * @description:
 * @author: 张修杰
 * @create: 2021-07-23 22:40
 **/
@Service
public class CarTypeServiceImpl implements CarTypeService {
    @Resource
    CarTypeMapper carTypeMapper;

    @Override
    public R selectAllCarType() {
        List<TbCarType> tbTypes =carTypeMapper.selectList(null);
        return R.ok().put("AlltbTypes",tbTypes);
    }
    @Override
    public R findAllCarTypePage(Integer currentPage, Integer pageSize, TypeVo typeVo) {

        QueryWrapper<TbCarType> wrapper=new QueryWrapper<>();

        if (StringUtils.isNotEmpty(typeVo.getTypeName())){
            wrapper.like("type_name",typeVo.getTypeName());
        }

        Page<TbCarType> page=new Page<>(currentPage,pageSize);
//        IPage<TbCar> page1=carConfigMapper.SaveCarList(page,wrapper);
        carTypeMapper.selectPage(page,wrapper);
        return R.ok().put("records",page.getRecords()).put("total",page.getTotal());

    }

    @Override
    public R updateCarTypeById(TbCarType tbCarType) {
        int i= carTypeMapper.updateById(tbCarType);
        return (i>0)? R.ok():R.error();
    }

    @Override
    public R selectCarTypeById(String id) {
        TbCarType tbCarType=carTypeMapper.selectById(id);
        return R.ok().put("tbCarType",tbCarType);
    }

    @Override
    public R insertCarType(TbCarType tbCarType) {
        int i= carTypeMapper.insert(tbCarType);
        return (i>0)? R.ok():R.error();
    }

    @Override
    public R deleteCarType(String id) {
        int i= carTypeMapper.deleteById(id);
        return (i>0)? R.ok():R.error();
    }
}
